﻿using eProcurement.BLL;
using eProcurement.controls;
using eProcurement.DAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace eProcurement.members
{
    public partial class Bidders : System.Web.UI.Page
    {
        protected void Page_Load( object sender, EventArgs e )
        {
            if ( !IsPostBack )
            {
                Manager manager = new Manager();
                List<Supplier> suppliers = manager.GetBidders( Convert.ToInt32( Request[ "pid" ] ) );
                foreach ( Supplier supplier in suppliers )
                {
                    if ( supplier.Bids.Count != 0 )
                    {
                        int pid = Convert.ToInt32( Request[ "pid" ] );
                        Bid bid = ( from i in supplier.Bids where i.ProjectId == pid select i ).FirstOrDefault();

                        if ( bid != null )
                        {
                            BidderItemControl control = (BidderItemControl)LoadControl( "../controls/BidderItemControl.ascx" );
                            control.Setup( bid );
                            container.Controls.Add( control );
                        }
                    }
                }
            }
        }
    }
}